package com.zlsy.thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhouliang
 * @date 2020/7/4 13:45
 * <p>
 * 演示：线程池是否停止
 */
public class IsShutdownThreadPool {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        for (int i = 0; i < 1000; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName());
                }
            });
        }

        executorService.shutdown();

        System.out.println("线程池是否已经停止？" + executorService.isShutdown());

        if (executorService.isShutdown()) {
            System.err.println("线程池已经停止无法再提交任务！");
        } else {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("提交一个线程的任务，当前线程:" + Thread.currentThread().getName());
                }
            });
        }
    }

}
